// pages/client/client.js
let conf = require('../../app.config').app
const systemInfo = wx.getSystemInfoSync();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bg_height:0,
    myinfo:{},
    customerHomeInfoResponse:{},
    pointsTotal:0,
    alertType: '',
    is_wanshan:-1,
    is_login:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let t = this;
    var w = systemInfo.windowWidth;
    var h = systemInfo.windowHeight;
    t.setData({
      bg_height:(880 / 750) * w,
    });

  },

  openinginformation(){
    let that = this;
    that.api.interface.openinginformation().then(res=>{
      console.log(res,' - -- - -- - -- >')
      wx.setStorageSync('time', res.data.data.dateNow)
      wx.setStorageSync('openinginformation', res.data.data)
      that.setData({
        customerHomeInfoResponse: res.data.data.customerHomeInfoResponse,

      })
    })
  },
  get_score(){
    let that = this;

    this.api.interface.integralMallContent().then(result => {
      if (result.data.data.remainPoint) {
        that.setData({
          pointsTotal: result.data.data.remainPoint,
        });
      }
    })
  },
  cli_points(){
    let t = this;
    var userinfo = wx.getStorageSync('userinfo');
    if(!userinfo){
      wx.navigateTo({ url:'../authorization/authorization?act='+6});
      return false;
    }
    wx.navigateTo({
      url: '../points/points',
    });
  },
  cli_coupon(){
    let t = this;
    wx.navigateTo({
      url: '../coupon/coupon',
    });
  },
  cli_addresslist(){
    let t = this;
    var userinfo = wx.getStorageSync('userinfo');
    if(!userinfo){
      wx.navigateTo({ url:'../authorization/authorization?act='+6});
      return false;
    }
    wx.navigateTo({
      url: '../addresslist/addresslist',
    });
  },
  cli_activity(){
    let t = this;
    wx.navigateTo({
      url: '../activity/activity',
    });
  },
  // 显示弹窗
  tapShowAlert(e) {
    this.setData({ alertType: '福利中心活动规则' })
  },
  onAlertClose() {
    this.setData({ alertType: '' })
  },
  go_info(){
    var userinfo = wx.getStorageSync('userinfo');
    if(!userinfo){
      wx.navigateTo({ url:'../authorization/authorization?act='+6});
      return false;
    }
    wx.navigateTo({
      url: '../info/info',
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let t = this;
    var logincode = wx.getStorageSync('logincode');
    if(logincode == 501){

      this.api.interface.getCustomerInfo().then(res => {
        console.log('ajax--getCustomerInfo',res.data.data);
        wx.setStorageSync('userinfo', res.data.data)
        this.setData({myinfo:res.data.data,is_login:1})
        this.openinginformation();
        this.get_score();
        if(res.data.data.birthday){
          t.setData({is_wanshan:1});
        }else{
          t.setData({is_wanshan:0});
        }

      });
    }else{

      this.api.login().then(res => {
        console.log('login----',res);
        if(res.data.code == 501){
          //获取用户信息
          this.api.interface.getCustomerInfo().then(res => {
            console.log('ajax--getCustomerInfo',res.data.data);
            wx.setStorageSync('userinfo', res.data.data)
            this.setData({myinfo:res.data.data})
            console.log(res.data.data);
            if(res.data.data.birthday){
              t.setData({is_wanshan:1});
            }else{
              t.setData({is_wanshan:0});
            }
            this.openinginformation();
            this.get_score();
          })
        }


      })
    }
  },
  cli_share(){
    let t = this;
    //wx.setStorageSync('is_share_jiangli',1);
    t.api.interface.customerInfoShare().then(res => {
      t.api.interface.integralMallContent().then(result => {
        if (result.data.data.remainPoint) {
          t.setData({
            pointsTotal: result.data.data.remainPoint,
          });
        }
      })
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    /*
    if(wx.getStorageSync('is_share_jiangli')){
      var userinfo = wx.getStorageSync('userinfo');
      wx.removeStorageSync('is_share_jiangli');
      return {
        title: conf.shareSettings.title,
        path: conf.shareSettings.path+"?share_openid="+userinfo.openId,
        imageUrl: conf.shareSettings.imageUrl,
      }

    }

     */

  }
})